#include<bits/stdc++.h>
#define int long long
#define N 100005
using namespace std;
int n;
int mn=1e18,p[N];
int ans=1e18;
pair<int,int> a[N];
signed main(){
    freopen("boast.in","r",stdin);
    freopen("boast.out","w",stdout);
    scanf("%lld",&n);
    for(int i=1;i<=n;i++) scanf("%lld %lld",&a[i].second,&a[i].first);
    sort(a+1,a+n+1);
    for(int i=1;i<=n;i++){
        p[i]=mn+a[i].first+a[i].second;
        mn=min(mn,a[i].second);
    }
    mn=1e18;
    for(int i=1;i<=n;i++){
        ans=min(ans,mn+a[i].first+a[i].second);
        mn=min(mn,p[i]);
    }
    printf("%lld",ans);
    return 0;
}